#ifndef __SPLASH_H__
#define __SPLASH_H__

#include "cocos2d.h"
#include "MenuScene.h"
#include "util.h"
USING_NS_CC;

namespace suta
{
	class SplashLayer:public CCLayer
	{
	public:
		bool init()
		{
			bool ret=false;
			do 
			{
				CC_BREAK_IF(!CCLayer::init());
				CCSprite*splashSprite=CCSprite::spriteWithFile("bg/splash.png");
				splashSprite->setPosition(ccp(400,240));
				addChild(splashSprite);
				splashSprite->setOpacity(0);
				
				CCDelayTime*delay1=CCDelayTime::actionWithDuration(1.0f);
				CCFadeIn*fade=CCFadeIn::actionWithDuration(2.0f);
				CCDelayTime*delay2=CCDelayTime::actionWithDuration(4.0f);
				CCCallFunc*call=CCCallFunc::actionWithTarget(this,callfunc_selector(SplashLayer::turn));
				splashSprite->runAction(CCSequence::actions(delay1,fade,delay2,call,NULL));

				SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(MUSIC_BACKGROUND);
				ret=true;
			} while (0);
			return ret;
		};
		void turn()
		{
			CCScene*scene=MenuScene::node();
			CCDirector::sharedDirector()->replaceScene(CCTransitionFade::transitionWithDuration(1.1f,scene));
		};
		LAYER_NODE_FUNC(SplashLayer);

		void onExit()
		{
			CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(MUSIC_BACKGROUND,true);
			CCLayer::onExit();
		};
	};

	class SplashScene:public CCScene
	{
	public:
		bool init()
		{
			bool ret=false;
			do 
			{
				CC_BREAK_IF(!CCScene::init());
				addChild(SplashLayer::node());
				ret=true;
			} while (0);
			return ret;
		};

		SCENE_NODE_FUNC(SplashScene);
	};
}//namespace suta

#endif//__SPLASH_H__